package com.test01;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class rmb_to_Dollar {
    public static void main(String[] args) {
        new Win();
    }
}
class Win extends JFrame {
    JFrame win = new JFrame("人民币转换为美元");
    JLabel l1 = new JLabel("人民币/元:      ");
    JLabel l2 = new JLabel("美元/Dollar:   ");
    JLabel l3 = new JLabel("(汇率:6.17)    ");
    Box v1 = Box.createHorizontalBox();
    Box h1 = Box.createVerticalBox();
    Box h2 = Box.createVerticalBox();
    JTextField t1 = new JTextField(10);
    JTextField t2 = new JTextField(10);
    JButton b1 = new JButton("转换");
    public void init() {
        win.setBounds(300,200,233,150);
        win.setLayout(new FlowLayout());
        b1.addActionListener(e -> {
            String rmb=t1.getText();
            t2.setText(Double.parseDouble(rmb)*6.17+" ");
        });
        h1.add(l1);h1.add(l2);h1.add(l3);v1.add(h1);
        h2.add(t1);h2.add(t2);h2.add(b1);v1.add(h2);
        win.add(v1);
    }
    public Win() {
        init();
        win.setVisible(true);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}